import java.awt.Dimension;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JComboBox;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JRadioButton;
import javax.swing.ButtonGroup;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.Random;
import javax.swing.JButton;
import javax.swing.border.TitledBorder;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.Component;
import java.awt.Font;
import java.awt.Color;
import javax.swing.ImageIcon;




public class StuPersonalInfo extends JFrame {

        /**
         * 
         */
        private static final long serialVersionUID = -8050292788489603573L;
        //private JPanel contentPane;
        private JTextField txtName;
        private JTextField textField;
        private JTextField textField_1;
        private JTextField textField_2;
        private JTextField textField_3;
        private JTextField textField_4;
        private final ButtonGroup buttonGroup = new ButtonGroup();
        private JTextField textField_5;
        private JTextField schoolName1;
        private JTextField major1;
        private JTextField yearOfGrad1;
        private JTextField gpa1;
        private JTextField schoolName2;
        private JTextField major2;
        private JTextField yearOfGrad2;
        private JTextField gpa2;
        private JTextField schoolName3;
        private JTextField major3;
        private JTextField yearOfGrad3;
        private JTextField gpa3;
        final JComboBox comboBox_2 ;
       

        /**
         * Launch the application.
         */
        

        /**
         * Create the frame.
         */
        public StuPersonalInfo(final String user)  {
                getContentPane().setBackground(Color.ORANGE);
                getContentPane().setForeground(Color.LIGHT_GRAY);
                setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                setBounds(100, 100,900, 700);
                getContentPane().setLayout(null);
                
                JLabel lblName = new JLabel("Name");
                lblName.setForeground(Color.RED);
                lblName.setFont(new Font("Lucida Grande", Font.PLAIN, 13));
                lblName.setBounds(40, 33, 61, 16);
                getContentPane().add(lblName);
                
                txtName = new JTextField();
                txtName.setText("");
                txtName.setBounds(194, 27, 214, 28);
                getContentPane().add(txtName);
                txtName.setColumns(10);
                
                JLabel lblDateOfBirth = new JLabel("Date of Birth");
                lblDateOfBirth.setForeground(Color.RED);
                lblDateOfBirth.setBounds(40, 61, 84, 16);
                getContentPane().add(lblDateOfBirth);
                
                textField = new JTextField();
                textField.setBounds(194, 55, 214, 28);
                getContentPane().add(textField);
                textField.setColumns(10);
                
                JLabel lblGender = new JLabel("Gender");
                lblGender.setForeground(Color.RED);
                lblGender.setBounds(40, 89, 61, 16);
                getContentPane().add(lblGender);
                
                String[] gender={"Male", "Female"};
                final JComboBox comboBox = new JComboBox();
                comboBox.setModel(new DefaultComboBoxModel(gender));
                comboBox.setBounds(194, 85, 214, 27);
                getContentPane().add(comboBox);
                
                JLabel lblAddress = new JLabel("Address");
                lblAddress.setForeground(Color.RED);
                lblAddress.setBounds(40, 117, 61, 16);
                getContentPane().add(lblAddress);
                
                textField_1 = new JTextField();
                textField_1.setBounds(194, 111, 214, 28);
                getContentPane().add(textField_1);
                textField_1.setColumns(10);
                
                final JComboBox comboBox_1 = new JComboBox();
                comboBox_1.setBounds(194, 270, 136, 27);
                getContentPane().add(comboBox_1);
                
                JLabel lblPermanentAddress = new JLabel("Permanent Address");
                lblPermanentAddress.setForeground(Color.RED);
                lblPermanentAddress.setBounds(40, 145, 121, 16);
                getContentPane().add(lblPermanentAddress);
                
                textField_2 = new JTextField();
                textField_2.setBounds(194, 139, 214, 28);
                getContentPane().add(textField_2);
                textField_2.setColumns(10);
                
                JLabel lblNewLabel = new JLabel("Contact Number");
                lblNewLabel.setForeground(Color.RED);
                lblNewLabel.setBounds(40, 173, 121, 16);
                getContentPane().add(lblNewLabel);
                
                textField_3 = new JTextField();
                
                textField_3.setBounds(194, 167, 214, 28);
                getContentPane().add(textField_3);
                textField_3.setColumns(10);
                
                JLabel lblNewLabel_1 = new JLabel("Email Address");
                lblNewLabel_1.setForeground(Color.RED);
                lblNewLabel_1.setBounds(40, 201, 121, 16);
                getContentPane().add(lblNewLabel_1);
                
                textField_4 = new JTextField();
                textField_4.setBounds(194, 195, 214, 28);
                getContentPane().add(textField_4);
                textField_4.setColumns(10);
                
                JLabel lblNewLabel_2 = new JLabel("Willing to tutor");
                lblNewLabel_2.setForeground(Color.RED);
                lblNewLabel_2.setBounds(35, 229, 103, 16);
                getContentPane().add(lblNewLabel_2);
                
                final JRadioButton rdbtnYes = new JRadioButton("Yes");
                rdbtnYes.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent arg0) {
                                ArrayList<String> code= new ArrayList<String>();
                                String check="";
                                if(comboBox_2.getSelectedItem().toString().equals("Biomedical Engineering")){
                    				check="BME%";
                    			}
                    			else if(comboBox_2.getSelectedItem().toString().equals("Electrical & Computer Engineering")){
                    				check="ECE%";
                    			}
                    			else if(comboBox_2.getSelectedItem().toString().equals("Biology")){
                    				check="BIO%";
                    			}
                    			else if(comboBox_2.getSelectedItem().toString().equals("Computer Science")){
                    				check="CS%";
                    			}
                    			else if(comboBox_2.getSelectedItem().toString().equals("Aerospace Engineering")){
                    				check="AE%";
                    			}
                                try{
                         Connection con = new Connect().getConnection();
                         Statement statement =con.createStatement();
                         ResultSet result = statement.executeQuery("SELECT Code FROM REGISTERS AS R,SECTION AS S,CRS_CODE AS CR WHERE R.Student_Username='" + user +"' AND R.Section_CRN=S.CRN AND S.Course_Title=CR.Course_Title AND(R.Grade='B' OR R.Grade='A') AND Code Like '"+check+"'");
                                     
                         while(result.next()){
                                        code.add(result.getString(1));
                                }
                         String[] crs = new String[code.size()];
                         for(int i=0;i<code.size();i++){
                                 crs[i]=code.get(i);
                         }
                         comboBox_1.setModel(new DefaultComboBoxModel(crs));
                        
                                }catch(Exception e){
                                       // JOptionPane.showMessageDialog(null,"Check Connection"); 
                                }
                        }
                        });
                buttonGroup.add(rdbtnYes);
                rdbtnYes.setBounds(194, 235, 71, 23);
                getContentPane().add(rdbtnYes);
                
                final JRadioButton rdbtnNo = new JRadioButton("No");
                buttonGroup.add(rdbtnNo);
                rdbtnNo.setBounds(287, 235, 61, 23);
                getContentPane().add(rdbtnNo);
                
                
                
                JLabel lblNewLabel_3 = new JLabel("New label");
                lblNewLabel_3.setBounds(40, 428, 37, -6);
                getContentPane().add(lblNewLabel_3);
                
                JLabel lblIfYesSelect = new JLabel("If Yes, select the courses \n");
                lblIfYesSelect.setBounds(40, 257, 165, 27);
                getContentPane().add(lblIfYesSelect);
                
                JLabel lblYouWillLike = new JLabel("you will like to tutor");
                lblYouWillLike.setBounds(40, 290, 153, 16);
                getContentPane().add(lblYouWillLike);
                
                
                
                textField_5 = new JTextField("");
                textField_5.setBounds(373, 268, 180, 28);
                getContentPane().add(textField_5);
                textField_5.setColumns(10);
                
                JButton button = new JButton("+");
                button.addMouseListener(new MouseAdapter() {
                        @Override
                        public void mouseClicked(MouseEvent arg0) {
                                String add=comboBox_1.getSelectedItem().toString();
                                List<String> list =  Arrays.asList(textField_5.getText().toString().split(","));
                                if(!list.contains(add)){
                                if(textField_5.getText() == null ||textField_5.getText().equals("")|| textField_5.getText().trim().length() ==0){
                                        textField_5.setText(add);
                                }else{
                                        textField_5.setText(textField_5.getText() +","+add);
                                }
                                }
                        }
                });
                button.setBounds(330, 269, 32, 29);
                getContentPane().add(button);
                
                JButton button_1 = new JButton("-");
                button_1.addMouseListener(new MouseAdapter() {
                        @Override
                        public void mouseClicked(MouseEvent e) {
                                String remove=textField_5.getText().toString();
                                char[] ret =remove.toCharArray();
                                for(int i=remove.length()-1;i>=0;i--){
                                        if(remove.charAt(i) == ','){
                                                ret[i]='\0';
                                                break;
                                        }
                                        else{
                                                ret[i]='\0';
                                        }
                                }
                                String out = new String(ret);
                                textField_5.setText(out);
                        }
                });
                button_1.setBounds(560, 269, 32, 29);
                getContentPane().add(button_1);
                
                JLabel lblMajor = new JLabel("Major");
                lblMajor.setForeground(Color.RED);
                lblMajor.setBounds(40, 318, 37, 16);
                getContentPane().add(lblMajor);
                
                String[] majors={"Aerospace Engineering", "Biology", "Biomedical Engineering", "Computer Science", "Electrical & Computer Engineering"};
                comboBox_2 = new JComboBox();
                comboBox_2.setModel(new DefaultComboBoxModel(majors));
                comboBox_2.setBounds(78, 309, 144, 27);
                getContentPane().add(comboBox_2);
                
                JLabel lblDegree = new JLabel("Degree");
                lblDegree.setForeground(Color.RED);
                lblDegree.setBounds(259, 318, 61, 16);
                getContentPane().add(lblDegree);
                
                final JComboBox comboBox_3 = new JComboBox();
                comboBox_3.setModel(new DefaultComboBoxModel(new String[] {"B.Sc", "M.Sc", "Ph.D"}));
                comboBox_3.setBounds(326, 314, 134, 27);
                getContentPane().add(comboBox_3);
                
                JPanel panel_1 = new JPanel();
                panel_1.setToolTipText("");
                panel_1.setBorder(new TitledBorder(null, "Previous Education", TitledBorder.LEADING, TitledBorder.TOP, null, null));
                panel_1.setBounds(6, 346, 657, 175);
                getContentPane().add(panel_1);
                panel_1.setLayout(null);
                
                final JPanel panel = new JPanel();
                panel.setBackground(Color.ORANGE);
                panel.setBounds(6, 18, 648, 151);
                panel_1.add(panel);
                panel.setLayout(null);
                
                JLabel lblNewLabel_4 = new JLabel("Name of Institution");
                lblNewLabel_4.setForeground(Color.RED);
                lblNewLabel_4.setBounds(18, 18, 130, 16);
                panel.add(lblNewLabel_4);
                
                JLabel lblDegree_1 = new JLabel("Major");
                lblDegree_1.setBounds(18, 47, 61, 16);
                panel.add(lblDegree_1);
                
                JLabel lblYearOfGraduation = new JLabel("Year of Graduation");
                lblYearOfGraduation.setForeground(Color.RED);
                lblYearOfGraduation.setBounds(18, 75, 130, 16);
                panel.add(lblYearOfGraduation);
                
                JLabel lblGpa = new JLabel("GPA");
                lblGpa.setForeground(Color.RED);
                lblGpa.setBounds(18, 103, 61, 16);
                panel.add(lblGpa);
                
                schoolName1 = new JTextField();
                schoolName1.setBounds(161, 12, 151, 28);
                panel.add(schoolName1);
                schoolName1.setColumns(10);
                
                major1 = new JTextField();
                major1.setBounds(161, 41, 151, 28);
                panel.add(major1);
                major1.setColumns(10);
                
                yearOfGrad1 = new JTextField();
                yearOfGrad1.setBounds(160, 69, 151, 28);
                panel.add(yearOfGrad1);
                yearOfGrad1.setColumns(10);
                
                gpa1 = new JTextField();
                gpa1.setBounds(161, 97, 151, 28);
                panel.add(gpa1);
                gpa1.setColumns(10);
                
                JLabel lblDegree_2 = new JLabel("Degree");
                lblDegree_2.setBounds(18, 131, 61, 16);
                panel.add(lblDegree_2);
                
                String[] deg=new String[] {"BS", "MS", "Ph.D", "High School Diploma"};
                final JComboBox degree1 = new JComboBox();
                degree1.setModel(new DefaultComboBoxModel(deg));
                degree1.setBounds(161, 127, 151, 27);
                panel.add(degree1);
                
                final JComboBox degree2 = new JComboBox();
                degree2.setModel(new DefaultComboBoxModel(deg));
                degree2.setBounds(346, 127, 130, 27);
                panel.add(degree2);
                
                final JComboBox degree3 = new JComboBox();
                degree3.setModel(new DefaultComboBoxModel(deg));
                degree3.setBounds(491, 127, 134, 27);
                panel.add(degree3);
                
                schoolName2 = new JTextField();
                schoolName2.setBounds(342, 12, 134, 28);
                panel.add(schoolName2);
                schoolName2.setColumns(10);
                
                major2 = new JTextField();
                major2.setBounds(342, 41, 134, 28);
                panel.add(major2);
                major2.setColumns(10);
                
                
                yearOfGrad2 = new JTextField();
                yearOfGrad2.setBounds(342, 69, 134, 28);
                panel.add(yearOfGrad2);
                yearOfGrad2.setColumns(10);
                
                
                gpa2 = new JTextField();
                gpa2.setBounds(342, 97, 134, 28);
                panel.add(gpa2);
                gpa2.setColumns(10);
                
                
                schoolName3 = new JTextField();
                schoolName3.setBounds(491, 12, 134, 28);
                panel.add(schoolName3);
                schoolName3.setColumns(10);
                
                major3 = new JTextField();
                major3.setBounds(491, 41, 134, 28);
                panel.add(major3);
                major3.setColumns(10);
                
                yearOfGrad3 = new JTextField();
                yearOfGrad3.setBounds(491, 69, 134, 28);
                panel.add(yearOfGrad3);
                yearOfGrad3.setColumns(10);
                
                gpa3 = new JTextField();
                gpa3.setBounds(491, 97, 134, 28);
                panel.add(gpa3);
                gpa3.setColumns(10);
                
                final JButton btnSubmit = new JButton("Submit");
                btnSubmit.setBounds(383, 563, 117, 29);
                getContentPane().add(btnSubmit);
                
                JLabel lblYyyymmdd = new JLabel("YYYY-MM-DD");
                lblYyyymmdd.setBounds(406, 61, 117, 16);
                getContentPane().add(lblYyyymmdd);
                
                
                
                
                JLabel lblEntriesInRed = new JLabel("Entries in red are required");
                lblEntriesInRed.setFont(new Font("Lucida Grande", Font.ITALIC, 13));
                lblEntriesInRed.setForeground(Color.BLUE);
                lblEntriesInRed.setBounds(40, 5, 165, 16);
                getContentPane().add(lblEntriesInRed);
                
                JRadioButton rdbtnSameAsAddress = new JRadioButton("Same as Address");
                rdbtnSameAsAddress.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent arg0) {
                                textField_2.setText(textField_1.getText());     
                                
                        }
                });
                
                JLabel lblNewLabel_5 = new JLabel("");
                lblNewLabel_5.setIcon(new ImageIcon(StuPersonalInfo.class.getResource("/resources/p-331002-georgia-tech-yellow-jackets-black-spare-tire-cover-jt-2324558420.jpg")));
                lblNewLabel_5.setBounds(547, 5, 201, 164);
                getContentPane().add(lblNewLabel_5);
                rdbtnSameAsAddress.setBounds(412, 141, 141, 23);
                getContentPane().add(rdbtnSameAsAddress);
                
                JButton btnStudentServices = new JButton("Student Services");
                btnStudentServices.addActionListener(new ActionListener() {
                	public void actionPerformed(ActionEvent e) {
                		dispose();
                		new StudentServices(user);
                	}
                });
                btnStudentServices.setBounds(527, 563, 136, 29);
                getContentPane().add(btnStudentServices);
                
                try{
                        
                        Connection con =Connect.getConnection();
                        
            Statement stat =con.createStatement();
            System.out.println("Yahh2!");
           ResultSet result = stat.executeQuery("SELECT * FROM STUDENT WHERE Username='"+user+"'");
           String add="";
           while(result.next()){
                   if((add=result.getString(3))!=null)
                   textField_1.setText(add);
                  if((add=result.getString(4))!=null)
                   txtName.setText(add);
                  if((add=result.getString(5))!=null)
                           textField_4.setText(add);
                  if((add=result.getString(6))!=null)
                          textField.setText(add);
                  if((add=result.getString(7))!=null)
                          textField_2.setText(add);
                if((add=result.getString(9))!=null)
                          textField_3.setText(add);
                if((add=result.getString(8))!=null){
                        for(int i=0;i<gender.length;i++){
                                if(add.equals(gender[i]))
                                        comboBox.setSelectedIndex(i);
                        }
                }
                if((add=result.getString(11))!=null){
                        for(int i=0;i<majors.length;i++){
                                if(add.equals(majors[i]))
                                        comboBox_2.setSelectedIndex(i);
                        }
                }
                
                
                
           }
        result = stat.executeQuery("SELECT * FROM ED_HISTORY WHERE Student_Username='"+ user +"'");
        Component component[]={schoolName1,yearOfGrad1,degree1,major1,gpa1,schoolName2,yearOfGrad2,degree2,major2,gpa2,schoolName3,yearOfGrad3,degree3,major3,gpa3};
        int i=-1;
        while(result.next()){
                i++;
                   if((add=result.getString(1))!=null)
                   ((JTextField)component[i]).setText(add);
                  i++;
                   if((add=result.getString(2))!=null)
                           ((JTextField)component[i]).setText(add);
                  i++;
                  if((add=result.getString(3))!=null){
                          if(add.equals(deg[0])){
                                  ((JComboBox)component[i]).setSelectedIndex(0);  
                          }
                          else if(add.equals(deg[1])){
                                  ((JComboBox)component[i]).setSelectedIndex(1);  
                          }
                          else if(add.equals(deg[2])){
                                  ((JComboBox)component[i]).setSelectedIndex(2);  
                          }
                          else{
                                  ((JComboBox)component[i]).setSelectedIndex(3);
                          }
                          }
                  i++;
                   if((add=result.getString(4))!=null)
                           ((JTextField)component[i]).setText(add);
                   i++;
                   if((add=result.getString(5))!=null)
                           ((JTextField)component[i]).setText(add);
           }
       
                }catch(Exception eb){
                       // JOptionPane.showMessageDialog(null,"Check Connection");
                }
                btnSubmit.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e)
            {
                if (!textField.getText().matches("((19|20)\\d{2})-([1-9]|0[1-9]|1[0-2])-(0[1-9]|[1-9]|[12][0-9]|3[01])")){
                        JOptionPane.showMessageDialog(null,"Enter correct date format 'YYYY-MM-DD'");
                }
                
                else if(!txtName.getText().matches("[A-Z][A-Za-z-]*+( [A-Z][A-Za-z-]*)")){
                        JOptionPane.showMessageDialog(null,"Enter proper full Name");
                }
                else if(textField_1.getText()==""||textField_1.getText()==null||textField_1.getText().trim().length() ==0){
                        JOptionPane.showMessageDialog(null,"Enter proper Address");
                }
                else if(textField_2.getText()==""||textField_2.getText()==null||textField_2.getText().trim().length() ==0){
                        JOptionPane.showMessageDialog(null,"Enter proper Permanent Address");
                }
                else if(textField_4.getText().matches("^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*" +
      "[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$")){
                        
                }
                
                
                else if(schoolName1.getText().equals("")|| schoolName1.getText().trim().length() ==0||schoolName1.getText() == null ){
                        if(gpa1.getText() == null ||gpa1.getText().equals("")|| gpa1.getText().trim().length() ==0){
                        	if(yearOfGrad1.getText() == null ||yearOfGrad1.getText().equals("")|| yearOfGrad1.getText().trim().length() ==0){
                                                JOptionPane.showMessageDialog(null,"Enter Complete Previous Education");
                                        }
                        }
                                }
                else if(!textField_3.getText().matches("[-+]?[0-9]*\\.?[0-9]+$")){
                        JOptionPane.showMessageDialog(null,"Enter proper phone Number(only numbers and + allowed)");
                }
                
                
                

                        
                
                
                

                        
                else{
                try {
                        
                         ResultSet res;
                        Connection con = Connect.getConnection();
                         Statement statement =con.createStatement();
                         String name = "'"+txtName.getText()+"',";
                         String dob = "'"+textField.getText()+"',";
                         String gender ="'"+comboBox.getSelectedItem().toString()+"'"+",";
                         String major ="'"+comboBox_2.getSelectedItem().toString()+"'"+",";
                         String addrs ="'"+textField_1.getText()+"'"+",";
                         String perm ="'"+textField_2.getText()+"'"+",";
                         String degree ="'"+comboBox_3.getSelectedItem().toString()+"'"+",";
           
                         String email = "'"+textField_4.getText()+"'";
                         char[] ret = new char[9];
                                ret[0] ='8';
                                Random gen= new Random();
                                char[] coll = {'0','1','2','3','4','5','6','7','8','9'};
                                for(int i=1;i<9;i++){
                                        
                                        ret[i] =  coll[gen.nextInt(10)];
                                };
                                String re =new String(ret);
                                int out =Integer.parseInt(re);
                                // dropdown
                                res =statement.executeQuery("SELECT Code FROM REGISTERS AS R,SECTION AS S,CRS_CODE AS CR WHERE R.Student_Username='" + user +"' AND R.Section_CRN=S.CRN AND S.Course_Title=CR.Course_Title AND(R.Grade='B' OR R.Grade='A')");
                         System.out.println("UPDATE STUDENT SET Name = "+name + "Gender = " + gender+ "Degree =" + degree + "Major = " + major+ "DOB =" + dob + "Addrs= " + addrs +"Perm_Adrss= "+perm+"Contact_No= '" +textField_3.getText() +"'," + "Email_ID =" + email +" WHERE Username='"+ user +"'" );
                                statement.executeUpdate("UPDATE STUDENT SET Name = "+name + "Gender = " + gender+ "Degree =" + degree + "Major = " + major+ "DOB =" + dob + "Addrs= " + addrs +"Perm_Adrss= "+perm+"Contact_No= '" +textField_3.getText() +"'," + "Email_ID =" + email +" WHERE Username='"+ user +"'" );
                         int coun=0;
                         if (rdbtnYes.isSelected()){
      
                          res =statement.executeQuery("SELECT Tutor_Identification FROM TUTOR");
                         while(res.next()){
                                 coun=res.getInt(1);
                                 if (coun == out){
                                         out++;
                                         res =statement.executeQuery("SELECT Tutor_Identification FROM TUTOR"); 
                                 }
                 }
                         
                         
                         }
                         statement.executeUpdate("DELETE FROM TUTOR WHERE Student_Username='" + user +"'");
                         statement.executeUpdate("DELETE FROM TUTOR_APP WHERE Student_Username='" + user +"'");
                         statement.executeUpdate("INSERT INTO TUTOR(Student_Username,Tutor_Identification) VALUES('" +user +"','" + out +"')" );
                         List<String> list =  Arrays.asList(textField_5.getText().toString().split(","));
                        List<String> courseTitles = new LinkedList<String>();
                         
                        for(int i=0;i<list.size();i++){
                                
                                ResultSet retur=statement.executeQuery("SELECT Course_Title FROM CRS_CODE WHERE Code='"+list.get(i)+ "'");
                                
                                while(retur.next())
                                        courseTitles.add(retur.getString(1));
                        }
                        
                                for(String in:courseTitles){
                                        
                                        statement.executeUpdate("INSERT INTO TUTOR_APP(Student_Username,Course_Title) VALUES('" +user +"','" + in +"')" );
                        }
                                
                                        
                        //Group_1
                        System.out.println("DELETE FROM ED_HISTORY WHERE Student_Username='" + user +"'");
                        statement.executeUpdate("DELETE FROM ED_HISTORY WHERE Student_Username='" + user +"'");
                        statement.executeUpdate("INSERT INTO ED_HISTORY(Name_of_School,Year_of_Grad,Degree,Major,GPA,Student_Username) VALUES('" +schoolName1.getText() +"','" + yearOfGrad1.getText()+"','" + degree1.getSelectedItem().toString()+"','" + major1.getText()+"','"+ Double.parseDouble(gpa1.getText())+"','"+ user  +"')" );
                        if(!schoolName2.getText().equals("")|| schoolName2.getText().trim().length() !=0||schoolName2.getText() != null ){
                        if(!gpa2.getText().equals("")|| gpa2.getText().trim().length() !=0){
                        	if(yearOfGrad2.getText() == null ||yearOfGrad2.getText().equals("")|| yearOfGrad2.getText().trim().length() ==0){
                                        statement.executeUpdate("INSERT INTO ED_HISTORY(Name_of_School,Year_of_Grad,Degree,Major,GPA,Student_Username) VALUES('" +schoolName2.getText() +"','" + yearOfGrad2.getText()+"','" + degree2.getSelectedItem().toString()+"','" + major2.getText()+"','"+ Double.parseDouble(gpa2.getText())+"','"+ user  +"')" );    
                        }
                        }
                }
                                
                        if(!schoolName3.getText().equals("")|| schoolName3.getText().trim().length() !=0){
                                if(!gpa3.getText().equals("")|| gpa3.getText().trim().length() !=0){
                                	if(yearOfGrad3.getText() == null ||yearOfGrad3.getText().equals("")|| yearOfGrad3.getText().trim().length() ==0){
                                        
                                                   System.out.println("INSERT INTO ED_HISTORY(Name_of_School,Year_of_Grad,Degree,Major,GPA,Student_Username) VALUES('" +schoolName3.getText() +"','" + yearOfGrad3.getText()+"','" + degree3.getSelectedItem().toString()+"','" + major3.getText()+"','"+ Double.parseDouble(gpa3.getText())+"','"+ user  +"')" );     
                                                statement.executeUpdate("INSERT INTO ED_HISTORY(Name_of_School,Year_of_Grad,Degree,Major,GPA,Student_Username) VALUES('" +schoolName3.getText() +"','" + yearOfGrad3.getText()+"','" + degree3.getSelectedItem().toString()+"','" + major3.getText()+"','"+ Double.parseDouble(gpa3.getText())+"','"+ user  +"')" );    
                        }
                                }
                
                }
                                
                        
                       dispose();
                       new HomePageStudent(user);
                       //con.close();
                        }               
                         
                         
           
                catch(Exception eb) {
                	//JOptionPane.showMessageDialog(getContentPane(),"Check Connection");       
                } finally {
                
            }
            }   
            }
                
                });
                

                setPreferredSize(new Dimension(700, 700));
                pack();
                setVisible(true);
                setTitle("Student Personal Info");
                setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        }
        public void addNewField()
        {
            getRootPane().validate();
            getRootPane().repaint();
            this.pack();
        }
        }